package com.czxy.Demo15;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        //  给定字符串
        String str = "<Dog name='小白' color='白色' sons='小黑,小花'/>";

        Dog d =new Dog();
        String name = getValue("name",str );
        String color = getValue("color", str);
        String sons = getValue("sons",str );

        d.setName(name);
        d.setColor(color);
        String[] ss = sons.split(",");
        ArrayList<String> list =new ArrayList<>();
        for (String s : ss) {
            list.add(s);
        }
        d.setSons(list);
        System.out.println(d);
    }
    public static String getValue(String name,String s){
        int start=s.indexOf(name+"='")+(name+"='").length();
        int end =s.indexOf("'",start);
        return s.substring(start,end);
    }
}
